<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/

namespace Hook\SendMail;
use Think\Behavior;
	
class SendMailBehavior extends Behavior {
 
	public function run(&$params){
		
		if(C('mailfunction')=='phpmailer'){
			require_once("PHPMailer/PHPMailerAutoload.php");
			
			$mail = new \PHPMailer(); //实例化
			$mail->IsSMTP(); // 启用SMTP
			$mail->Host=C('mailsmtp'); //smtp服务器的名称
			$mail->SMTPAuth = true; //启用smtp认证
			$mail->Username = C('mailloginname'); //你的邮箱名
			$mail->Password = C('mailloginpassword') ; //邮箱密码
			$mail->From = C('mailloginname'); //发件人地址
			$mail->FromName = C('sitename'); //发件人姓名
			
			$mail->AddAddress($params['mailto']);
			$mail->WordWrap = 100; //设置每行字符长度
			$mail->IsHTML(true); // 是否HTML格式邮件
			$mail->CharSet=C('S_CHARSET'); //设置邮件编码
			$mail->Subject =$params['mailsubject']; //邮件主题
			$mail->Body = $params['mailcontent']; //邮件内容
			return($mail->Send());
			
		}else{
			require_once("FoxSendMail.php");
		
			/* 格式
				$params=array(
					//接收者
					'mailto'=>'',
					//邮件标题
					'mailsubject'=>'',
					//邮件内容
					'mailcontent'=>'',
					//发送者
					'mailfrom'=>'',
					//发送者名称,默认网站名称
					'sendname'=>''
				);
			*/
			
			$sendmail = new \SendMail($params['mailto'],$params['mailsubject'],$params['mailcontent'],$params['mailfrom'],$params['sendname']);			
			$sendmail->FoxPHPSendMail();
			return true;
		}

	}
}

?>